<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<script src="js/mui.min.js"></script>
		<script type="text/javascript" src="js/immersed.js" ></script>
		<link href="css/mui.min.css" rel="stylesheet" />
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript" src="js/crypto-js.min.js" ></script>
		<style type="text/css">
			.btn {
				width: 96%;
				height: 50px;
				margin-top: 50px;
				margin-left: 2%;
				text-align: center;
				line-height: 50px;
				background: #0062CC;
				color: #FFFFFF;
				border-radius: 5px;
			}
		</style>·
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			
			<h1 class="mui-title" >条码扫描</h1>
		</header>
		<div class="mui-content mui-fullscreen">
			<!--<div class="btn"    onclick="clicked('barcode_scan2.html',true,true)">条码扫描</div>-->
			<div class="mui-card-footer">
				<!--<button  class="mui-btn mui-btn-primary" onclick="clicked('barcode_scan2.html',true,true)"  >开始扫描</button>-->
				<button  class="mui-btn mui-btn-warning" onclick='reset()'>重置信息</button>
				<button  class="mui-btn mui-btn-primary" id="creatdata">进炉</button>
			</div>
			
			<div class="mui-input-group">
				<input type="hidden" id="codeno" />
			    <div class="mui-input-row">
			        <label>条码内容</label>
			    	<input type="text" id="text1" class="mui-input-clear" autofocus="autofocus">
			    </div>
			    <div class="mui-input-row">
			        <label>确认内容</label>
			        <!--onblur="losejd(2)"-->
			        <input type="text" id="text2" class="mui-input-clear" onblur="losejd(2)">
			    </div>
			    <div class="mui-input-row">
			        <label>再次确认</label>
			        <!--onblur="losejd(3)"-->
			        <input type="text" id="text3" class="mui-input-clear" onblur="losejd(3)">
			    </div>
			</div>
			<h4 id='messages' style="color:red"></h4>
			
			<div class="btn"  id="getDead" style="display: none;">获取逝者信息</div>
		
			<h3 id="regName"></h3>
			<h3 id="regSex"></h3>
			<h3 id="regAge"></h3>
			<h3 id="hjadress"></h3>
			<h3 id="checkStatus"></h3>
			<h3 id="relateName"></h3>
		</div>
		
		<script type="text/javascript" src="js/crypto-js.min.js"></script>

		<script type="text/javascript" charset="utf-8">
			var deadInfo=document.getElementById('deadInfo');
			//文本输入框
			var t1=document.getElementById('text1');
			var t2=document.getElementById('text2');
			var t3=document.getElementById('text3');
			var code=document.getElementById('codeno');
			//逝者信息显示区域
			var regName=document.getElementById('regName');
			var relateName=document.getElementById('relateName');
			var creNum=document.getElementById('creNum');
			var regSex=document.getElementById('regSex');
			var regAge=document.getElementById('regAge');
			var hjadress=document.getElementById('hjadress');
			//机构ID
			var orgId='';
			var regId='';
			//ajax请求公有部分，请求头
			var BASEURL='http://192.168.0.199:8096/api';
			var DATA= '{}';
			var DATATYPE="json";
			var TYPE="post";
			var TIMEOUT=10000;
			mui.init();
			var mask=mui.createMask();//遮罩层
			mui.plusReady(function(){

			});
			
			document.getElementById("getDead").addEventListener('tap', function(){getOrgId();});
			document.getElementById("creatdata").addEventListener('click', function(){creatdatas();});
		function reset(){
			t1.value=null;
			t2.value=null;
		    t3.value=null;
		    code.value=null;
		    t1.focus();
			document.getElementById('regName').innerHTML='';
			document.getElementById('relateName').innerHTML='';
			document.getElementById('checkStatus').innerHTML='';
			document.getElementById('regSex').innerHTML='';
			document.getElementById('regAge').innerHTML='';
			document.getElementById('hjadress').innerHTML='';
			document.getElementById('messages').innerHTML='';
			document.getElementById('getDead').style.display='none';
		}
	function headersBody(data) {//请求体
        const str = JSON.stringify(data)
        return {
            AccessId: 'achance',
            reqtime: Date.now(),
            version: '1.0.0',
            sign: CryptoJS.MD5(JSON.stringify(data)).toString(),
            reqlength: str.length,
            'Content-Type':'application/json',
        }
        
    }
	function test()
        {
          getOrgId();
        }
			//获取机构信息
			function getOrgId(){
			mui.ajax(BASEURL+'/Login/QueryOrgan',{
					data:JSON.stringify(DATA),
					dataType: DATATYPE,//服务器返回json格式数据
					type:TYPE,//HTTP请求类型
					timeout:TIMEOUT,//超时时间设置为10秒；
					async:true,
					headers:headersBody(DATA),
					beforeSend: function() {
	        			plus.nativeUI.showWaiting( "等待中..." );
	        			mask.show();//显示遮罩层
    				},
    				complete: function() {
	        			plus.nativeUI.closeWaiting();
	        			mask.close();//关闭遮罩层
    				},
					success:function(data,textStatus,xhr){
						//服务器返回响应，根据响应结果，分析是否登录成功；
						var companys = data.content;
        				orgId = companys[0].ORGID;
        				this.getDeath();
					},
					error:function(xhr,type,errorThrown){
						//异常处理；
						console.log(type);
						alert('网络请求失败,请稍后再试');
					}
			});
				console.log(orgId);
			}
			//进炉
			function creatdatas(){
				if(t1.value && regId){
				var data={
					TSHREGID:regId
				};
				mui.ajax(BASEURL+'/Takeash/CreCreate',{
					data:JSON.stringify(data),
					dataType: DATATYPE,//服务器返回json格式数据
					type:TYPE,//HTTP请求类型
					timeout:TIMEOUT,//超时时间设置为10秒；
					headers:headersBody(data),
					
					success:function(data,textStatus){
						this.reset();
                        alert('进炉成功！')
						
					},
				
					error:function(xhr,type,errorThrown){
						//异常处理；
						alert('数据错误');
					}
				});
				}else{
					alert('缺少必填信息')
				}
			};
			//获取逝者信息
			function getDeath(){
				if(t1.value && orgId){
					
				var data={
					REGBUSNUM:t1.value,
					REGORGID:orgId
				};
				mui.ajax(BASEURL+'/Registration/GetRegistrationByNoAn',{
					data:JSON.stringify(data),
					dataType: DATATYPE,//服务器返回json格式数据
					type:TYPE,//HTTP请求类型
					timeout:TIMEOUT,//超时时间设置为10秒；
					headers:headersBody(data),
					
					success:function(data,textStatus){
					
						var regData=data.content;
						regName.innerHTML='逝者姓名：'+regData.REGNAME;
						regSex.innerHTML='逝者性别：'+regData.REGSEXDESC;
						regAge.innerHTML='逝者年龄：'+regData.REGAGE;
						hjadress.innerHTML='户籍地址：'+regData.REGDETAILADDRESS;
						checkStatus.innerHTML='结账状态：'+regData.CHDSTATUSDESC;
						relateName.innerHTML='家属姓名：'+regData.REGHANDLERNAME;
						regId = regData.REGID;
					},
				
					error:function(xhr,type,errorThrown){
						//异常处理；
						console.log(type);
						alert('数据错误');
					}
				});
				}else{
					alert('缺少必填信息')
				}
			};
			//扫描返回结果
			function scaned(type, result, f){
				if(t1.value===null||t1.value.length===0)
				{
				   t1.value=result;
				   code.value=null;
				   return;
				}
				if(t2.value===null||t2.value.length===0){
					t2.value=result;
					code.value=null;
					if(t1.value!=t2.value)
					  document.getElementById('messages').innerHTML='条码信息不一致';
					return;
				}
				if(t3.value===null||t3.value.length===0)
				{
					t3.value=result;
					if(t2.value!=t3.value)
					{
					  document.getElementById('messages').innerHTML='条码信息不一致';
					  return;
					}
				}
				else
				 return;
				if(t1.value!=t2.value||t1.value!=t3.value)
				{
					document.getElementById('messages').innerHTML='条码信息不一致';
					return;
				}
				code.value=result;
			    document.getElementById('messages').innerHTML='';
				document.getElementById('getDead').style.display='block';
			}
			//自动切换焦点
			function tabForward(event){
		        var target = event.target || event.srcElement; //当前事件对象
		        if (target.value.length == 13) {//判断是否与目标字符数相等
		            var form = document.getElementsByClassName("mui-input-clear");//获取输入框
		            var len = form.length;
		            var i;
		            
		            for (i=0;i<len;i++){
		                if(form[i] == target){
		                    if( form[i+1]){
		                        form[i+1].focus();//向下一个获取焦点
		                    }else{
		                    	form[i].blur();//最后一个失去焦点
		                    }
		                    return;
		                }
		            }
		        }
		    }
			function losejd(val){
//				console.log(val);
//				console.log(t1.value);
//				console.log(t2.value);
//				console.log(t3.value);
				//手持设备红外扫描版的
				if(val === 2){
					if(t1.value!=t2.value){
						document.getElementById('messages').innerHTML='条码信息不一致';
						return;
					}
				}
				if(val === 3) {
					if(t2.value!=t3.value){
						document.getElementById('messages').innerHTML='条码信息不一致';
						return;
					}
				}
				if(t1.value == t2.value && t2.value == t3.value && t1.value != null){
					document.getElementById('messages').innerHTML='';
					document.getElementById('getDead').style.display='block';
				}
//				调摄像头版本的
//				if(t1.value!=t2.value||t1.value!=t3.value)
//				{
//					document.getElementById('messages').innerHTML='条码信息不一致';
//					return;
//				}
//				document.getElementById('messages').innerHTML='';
//				document.getElementById('getDead').style.display='block';
//				
//				if(t1.value===null||t1.value.length===0)
//				{
//				   t1.value=result;
//				   code.value=null;
//				   return;
//				}
//				if(t2.value===null||t2.value.length===0){
//					t2.value=result;
//					code.value=null;
//					if(t1.value!=t2.value)
//					  document.getElementById('messages').innerHTML='条码信息不一致';
//					return;
//				}
//				if(t3.value===null||t3.value.length===0)
//				{
//					t3.value=result;
//					if(t2.value!=t3.value)
//					{
//					  document.getElementById('messages').innerHTML='条码信息不一致';
//					  return;
//					}
//				}
//				else
//				 return;
//				if(t1.value!=t2.value||t1.value!=t3.value)
//				{
//					document.getElementById('messages').innerHTML='条码信息不一致';
//					return;
//				}
//				code.value=result;
//			    document.getElementById('messages').innerHTML='';
//				document.getElementById('getDead').style.display='block';

//*************************************************
			}
			t1.onkeyup = tabForward;
			t2.onkeyup = tabForward;
			t3.onkeyup = tabForward;
		</script>
	</body>

</html>